package cn.chia.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.chia.back.dao.IOrderDAO;
import cn.chia.front.dao.IOrderFrontDAO;
import cn.chia.pojo.Orderitems;
import cn.chia.pojo.Orders;
import cn.chia.service.OrderService;

@Service
public class OrderServiceImpl implements OrderService {
	private IOrderDAO iOrderDao;
	private IOrderFrontDAO iOrderFrontDdao;
	
	@Resource(name="orderDAOImpl")
	public void setiOrderDao(IOrderDAO iOrderDao) {
		this.iOrderDao = iOrderDao;
	}
	
	@Resource(name="orderFrontDAOImpl")
	public void setiOrderFrontDdao(IOrderFrontDAO iOrderFrontDdao) {
		this.iOrderFrontDdao = iOrderFrontDdao;
	}

	/*
	 * 于辉  根据id查找订单(后台)
	 */
	public Orders findById(Integer id) throws Exception {
		return iOrderFrontDdao.findById(id);
	}
	/*
	 * 于辉  根据id查找订单(前台)
	 */
	public Orders findFrontById(Integer id) throws Exception {
		return iOrderDao.findById(id);
	}
	/*
	 * 于辉  查询所有订单(后台)
	 */
	public List<?> findall() throws Exception {
		return iOrderDao.findAll();
	}
	/*
	 * 于辉  查询所有订单(前台)
	 */
	public List<?> findallfront() throws Exception {
		return iOrderFrontDdao.findAll();
	}
	/*
	 * 于辉  得到所有订单数
	 */
	public int getAllCount() throws Exception {
		return iOrderDao.getCount();
	}
	/*
	 * 于辉  修改订单(后台)
	 */
	public void update(Orders vo) throws Exception {
		iOrderDao.doUpdate(vo);
	}
	/*
	 * 于辉  修改订单(前台)
	 */
	public void updateFront(Orders vo) throws Exception {
		iOrderFrontDdao.doUpdate(vo);
	}
	/*
	 * 于辉  根据状态查找订单(前台)
	 */
	public List<?> findOrdersByState(String state) throws Exception {
		return iOrderFrontDdao.findOrdersByState(state);
	}
	/*
	 * 于辉  根据状态查找订单(后台)
	 */
	public List<?> findOrdersByStateBack(String state) throws Exception {
		return iOrderDao.findOrdersByState(state);
	}
	
	public Map<String, Object> map (int pageNo, int pageSize, String keyword, String column) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("allOrders", iOrderDao.findAll(pageNo, pageSize, keyword, column));
		map.put("count", iOrderDao.getAllCount(keyword, column));
		return map;
	}
	
	//李胜 增加订单
	public void add(Orders vo) throws Exception {
		// TODO Auto-generated method stub
		iOrderDao.doCreate(vo);
	}
	//李胜 通过订单号找订单
	public Orders findByNumber(String number) throws Exception {
		// TODO Auto-generated method stub
		return iOrderDao.findByNumber(number);
	}
	//李胜 存订单明细
	public void addOrderItems(Orderitems vo) throws Exception {
		// TODO Auto-generated method stub
		iOrderDao.addOrderItems(vo);
	}

	public Orders findByOrderNumber(String findByOrderNumber) throws Exception {
		return (Orders)(iOrderFrontDdao.findByOrderNumber(findByOrderNumber).get(0));
	}

	public List<?> findOverdueOrders() throws Exception {
		return iOrderDao.findOverdueOrders();
	}

	public List<?> findordersbystateuszdtime(String state, String uszdtime)
			throws Exception {
		return iOrderDao.findordersbystateuszdtime(state, uszdtime);
	}

}
